import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  server: {
    proxy: {
      // 处理HTTP API请求
      '/api': {
        target: 'http://localhost:8090',
        changeOrigin: true,
        // 保留/api前缀
      },
      // 专门处理WebSocket请求
      '/ws': {
        target: 'http://localhost:8090',
        changeOrigin: true,
        ws: true,
        // 添加重写规则确保SockJS请求正确转发
        rewrite: (path) => path
      },
      // 处理SockJS特有的信息请求
      '/ws/info': {
        target: 'http://localhost:8090',
        changeOrigin: true,
        ws: false,
        rewrite: (path) => '/ws/info'
      }
    }
  }
})
